#!/usr/bin/python
#  -*- coding: utf-8 -*-
from wtforms import Form, StringField, IntegerField, TimeField
from wtforms.validators import Email, Length, InputRequired, EqualTo, Regexp, NumberRange, AnyOf
from apps.common.forms import BaseForm
from wtforms import ValidationError
from flask import g
from apps.api.models import User


class LoginForm(BaseForm):
    username = StringField(validators=[InputRequired(message='请输入用户名或手机号')])
    password = StringField(validators=[Length(4, 20, message='密码格式输入错误')])
    remember = StringField()


class ResetPwdForm(BaseForm):
    old_pwd = StringField(validators=[Length(4, 20, message='密码格式输入错误')])
    new_pwd = StringField(validators=[Length(4, 20, message='密码格式输入错误')])
    new_pwd1 = StringField(validators=[EqualTo("new_pwd", message="两次密码输入不相同")])


class AddPushForm(BaseForm):
    big_img = StringField(validators=[Length(0, 10000, message='图片超出上限')])
    small_img = StringField(validators=[Length(0, 10000, message='图片超出上限')])
    title = StringField(validators=[Length(0, 10000, message='标题')])
    url = StringField(validators=[Length(0, 10000, message='跳转链接')])
    priority = StringField(validators=[Length(0, 10000, message='优先级')])


class UpdatePush(AddPushForm):
    push_id = IntegerField(validators=[InputRequired(message='请输入轮播图id')])


class ModifyForm(BaseForm):
    phone = StringField(validators=[Regexp(r"1[3456789]\d{9}", message='请输入正确格式的手机号码！')])
    username = StringField(validators=[Regexp(r".{2,20}", message='请输入正确格式的用户名！')])
    address = StringField()
    address_img = StringField()
    user_id = StringField(validators=[InputRequired(message='请输入用户id')])

    # def validate_phone(self, field):
    #     phone = field.data
    #     user_id = self.user_id
    #     user_phone = User.query.filter_by(phone=phone).first()
    #     user = User.query.filter_by(id=user_id).first()
    #     if user.phone != phone and user_phone:
    #         raise ValidationError(message='手机号已被注册！')

    # def validate_username(self, field):
    #     username = field.data
    #     user_id = self.user_id
    #     user_name = User.query.filter_by(nicakname=username).first()
    #     user = User.query.filter_by(id=user_id).first()
    #     if user.username != username and user_name:
    #         raise ValidationError(message='昵称已被注册！')


class UnblockForm(BaseForm):
    id = StringField(validators=[InputRequired(message='请输入用户id')])


class BlockadeForm(UnblockForm):
    token = StringField(validators=[InputRequired(message='请输入封号原因')])


class TradeForm(BaseForm):
    trade_id = IntegerField(validators=[InputRequired('请输入id')])
    start_time = StringField(validators=[InputRequired('请输入开始时间')])
    end_time = StringField(validators=[InputRequired('请输入结束时间')])


class AddBannerForm(BaseForm):
    name = StringField(validators=[InputRequired(message='请输入轮播图名称')])
    image_url = StringField(validators=[InputRequired(message='请输入图片链接')])
    link_url = StringField()
    priority = IntegerField(validators=[InputRequired(message='请输入图片优先级')])
    goods_id = StringField()
    rich_text = StringField()
    status = StringField()
    id = StringField()


class UpdateBanner(AddBannerForm):
    banner_id = IntegerField(validators=[InputRequired(message='请输入轮播图id')])


class AddPayAccount(BaseForm):
    pay_card = StringField()
    # bank_name = StringField(validators=[InputRequired(message='请输入开户银行')])
    real_name = StringField()
    pay_img = StringField()
    pay_name = StringField()


class UpdateAccountForm(AddPayAccount):
    account_id = IntegerField(validators=[InputRequired(message='请输入账户id')])


class UpdateMoneyForm(BaseForm):
    global_params = StringField(validators=[InputRequired(message='请输入价格')])
    # trend = StringField(validators=[InputRequired(message='请输入潮通证价格')])
    # proportion = StringField(validators=[InputRequired(message='请输入释放百分比')])
    money_id = IntegerField(validators=[InputRequired(message='请输入id')])


class PayImgForm(BaseForm):
    pay_img = StringField(validators=[InputRequired(message='请输入付款图片')])
    order_id = IntegerField(validators=[InputRequired(message='请输入付款图片')])


class AddTypeForm(BaseForm):
    name = StringField(validators=[InputRequired(message='请输入商品名称')])
    # status = IntegerField(validators=[InputRequired(message='请选择状态')])
    small_img = StringField(validators=[InputRequired(message='请输入小图链接')])
    big_img = StringField()
    priority = IntegerField(validators=[InputRequired(message='请输入优先级')])


class UpdateType(AddTypeForm):
    type_id = StringField()


# 修改商品标签
class AddLabelForm(BaseForm):
    name_1 = StringField(validators=[InputRequired(message='请输入标签名称1')])
    name_2 = StringField(validators=[InputRequired(message='请输入标签名称2')])
    # type_img = StringField(validators=[InputRequired(message='请输入图片链接')])
    priority = IntegerField(validators=[InputRequired(message='请输入图片优先级')])
    label_id = StringField()
    status = StringField()


# 商品
class AddGoodsForm(BaseForm):
    name = StringField(validators=[InputRequired(message='请输入商品名称')])
    # goods_img = StringField(validators=[InputRequired(message='请输入图片链接')])
    fees = StringField(validators=[InputRequired(message='请输入手续费')])
    price = StringField(validators=[InputRequired(message='请输入当前价格')])
    stock_c = StringField(validators=[InputRequired(message='请输入库存')])
    # goods_type = StringField()
    priority = IntegerField(validators=[InputRequired(message='请输入优先级')])
    goods_code = StringField(validators=[InputRequired(message='请输入商品码')])
    low_price = StringField(validators=[InputRequired(message='请输入商品码')])
    high_price = StringField(validators=[InputRequired(message='请输入商品码')])
    status = StringField(validators=[InputRequired(message='请选择状态')])

    goods_id = StringField()
    # data_id = StringField()


# class UpdateGoods(AddGoodsForm):
#     goods_id = IntegerField(validators=[InputRequired(message='请输入商品id')])


# 商品详情
class AddDetailForm(BaseForm):
    goods_img = StringField(validators=[InputRequired(message='请输入图片链接')])
    data_id = IntegerField(validators=[InputRequired(message='请输入类型')])
    priority = IntegerField(validators=[InputRequired(message='请输入图片优先级')])


class UpdateDetail(AddDetailForm):
    detail_id = StringField()
    goods_id = IntegerField(validators=[InputRequired(message='请输入商品id')])


class AddMarketForm(BaseForm):
    name = StringField(validators=[InputRequired(message='请输入名称')])
    market_img = StringField(validators=[InputRequired(message='请输入图片链接')])
    number = StringField(validators=[InputRequired(message='请输入数量')])
    rise = StringField(validators=[InputRequired(message='请输入涨跌幅')])
    priority = IntegerField(validators=[InputRequired(message='请输入图片优先级')])
    price = StringField(validators=[InputRequired(message='请输入价格')])


class UpdateMarket(AddMarketForm):
    market_id = IntegerField(validators=[InputRequired(message='请输入id')])


# 优惠券
class AddCouponsForm(BaseForm):
    name = StringField(validators=[InputRequired(message='请输入名称')])
    coupons_img = StringField(validators=[InputRequired(message='请输入图片地址')])
    # price = StringField(validators=[InputRequired(message='请输入抵扣价格')])
    status = IntegerField(validators=[InputRequired(message='请选择状态')])
    expiration_time = IntegerField(validators=[InputRequired(message='请输入过期时间')])
    price = StringField(validators=[InputRequired(message='请输入满减金额')])
    minus_price = StringField(validators=[InputRequired(message='请输入满减金额')])
    coupons_id = StringField()


# 更新店铺
class UpdateStoreForm(BaseForm):
    name = StringField(validators=[InputRequired(message='请输入标签名称')])
    priority = IntegerField(validators=[InputRequired(message='请输入优先级')])
    content = StringField(validators=[InputRequired(message='请输入内容')])
    store_img = StringField(validators=[InputRequired(message='请输入图片地址')])
    store_id = StringField()


class UpdateArticleForm(BaseForm):
    title = StringField(validators=[InputRequired(message='请输入标题')])
    # priority = IntegerField(validators=[InputRequired(message='请输入优先级')])
    # content = StringField(validators=[InputRequired(message='请输入内容')])
    article_time = StringField(validators=[InputRequired(message='请输入日期')])
    # author = StringField(validators=[InputRequired(message='请输入发布作者')])
    article_img = StringField(validators=[InputRequired(message='请输入图片地址')])
    # type_id = StringField(validators=[InputRequired(message='请选择分类')])
    article_id = StringField()
    # goods_store_list = StringField()
    # goods_id_list = StringField()

